#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
#装饰器基础
# def foo():
#     print('foo')
#
# def bar(func):
#     func()
#
# bar(foo)
#
# #原始功能
# def use_logggin(func):
#     logging.warn("%s is runing" % func.__name__)
#     func()
#
# def foo():
#     print('i am foo')
#
# use_logggin(foo)

#简单装饰器
def usr_loggin(func):
    def warper():
        logging.warn("%s is runing1" % func.__name__)
        return func()
    return warper

@usr_loggin
def foo1():
    print("i am is foo1")

foo1()

#带参数的装饰器
def logusr1(leve):
    def usr_1(func):
        def warapp(*args):
            if leve == 1:
                logging.warn("%s is runing2" % func.__name__)
            return func(*args)
        return warapp
    return usr_1


@logusr1(2)
def foo2(name):
    print("name is %s" % name)

foo2("gaofan")